package com.eece411.project.p2;

public class SyncThread implements Runnable {
	// Information for replication
	private boolean isPut;
	private byte[] key;
	private byte[] data;
	private Instance i;

	// Constructor for put
	public SyncThread(Instance i,byte[] key,byte[] data){
		this.key=key;
		this.data=data;
		this.i=i;
		this.isPut=true;
	}
	
	// Constructor for remove
	public SyncThread(Instance i,byte[] key){
		this.key=key;
		this.i=i;
		this.isPut=false;
	}
	
	@Override
	public void run() {
		try {
			// Do the command on the Instance
			if(this.isPut){
				this.i.put(key, data, true);
			} else {
				this.i.remove(key,true);
			}
			System.out.println("--- Sync ok on key : "+new String(key));
		} catch (deadException e) {
			System.out.println("--- Sync not ok on key : "+new String(key));
		}
	}
}
